package com.mall.module.system.service.Impl;

import com.mall.module.system.domain.entity.SysPermission;
import com.mall.module.system.mapper.SysPermissionMapper;
import com.mall.module.system.service.SysPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 权限服务实现类
 */
@Service
public class SysPermissionServiceImpl implements SysPermissionService {

    @Autowired
    private SysPermissionMapper sysPermissionMapper;
    
    /**
     * 获取用户权限标识集合
     *
     * @param userId 用户ID
     * @return 权限标识集合
     */
    @Override
    public Set<String> getPermissionsByUserId(Long userId) {
        List<SysPermission> permissionList = sysPermissionMapper.selectPermissionsByUserId(userId);
        
        // 如果没有权限，返回空集合
        if (permissionList == null || permissionList.isEmpty()) {
            return new HashSet<>();
        }
        
        // 提取权限标识
        return permissionList.stream()
                .map(SysPermission::getPermissionKey)
                .collect(Collectors.toSet());
    }
    
    /**
     * 根据权限ID获取权限标识
     *
     * @param permissionId 权限ID
     * @return 权限标识
     */
    @Override
    public String getPermissionKeyById(Long permissionId) {
        if (permissionId == null) {
            return null;
        }
        return null;
    }
} 